﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CMS_GYM
{
    public class clsSaoLuuDAO
    {

        /// <summary>
        /// Kết nối SQL Server
        /// </summary>
        public CSQLServer sqlServer = new CSQLServer();

        /// <summary>
        /// Lấy DS khách hàng
        /// </summary>
        public clsSaoLuuDTO LayThongTin()
        {
            clsSaoLuuDTO SaoLuu = new clsSaoLuuDTO();
            string sql = "sp_GetInfoSaoLuu";
            DataTable table = sqlServer.readData(sql);
            if (table.Rows.Count == 1)
            {
                SaoLuu.id =int.Parse( table.Rows[0]["id"].ToString());
                SaoLuu.Thu2=bool.Parse( table.Rows[0]["Thu2"].ToString());
                SaoLuu.Thu3 = bool.Parse(table.Rows[0]["Thu3"].ToString());
                SaoLuu.Thu4 = bool.Parse(table.Rows[0]["Thu4"].ToString());
                SaoLuu.Thu5 = bool.Parse(table.Rows[0]["Thu5"].ToString());
                SaoLuu.Thu6 = bool.Parse(table.Rows[0]["Thu6"].ToString());
                SaoLuu.Thu7 = bool.Parse(table.Rows[0]["Thu7"].ToString());
                SaoLuu.Thu1 = bool.Parse(table.Rows[0]["Thu1"].ToString());
                SaoLuu.DuongDan = table.Rows[0]["DuongDan"].ToString();
                SaoLuu.ThoiGian = DateTime.Parse(table.Rows[0]["ThoiGian"].ToString());
            }
            return SaoLuu;
        }

     
        /// <summary>
        /// Cập nhật khách hàng
        /// </summary>
        public int Sua(clsSaoLuuDTO SaoLuu)
        {
            int i = -1;
            string sql = "sp_UpdateSaoLuu";
            string[] ParameterColection = new string[10];
            Object[] valueofParameter = new Object[10];
            ParameterColection[0] = "@id";
            valueofParameter[0] = SaoLuu.id;
            ParameterColection[1] = "@Thu1";
            valueofParameter[1] = SaoLuu.Thu1;
            ParameterColection[2] = "@Thu2";
            valueofParameter[2] = SaoLuu.Thu2;
            ParameterColection[3] = "@Thu3";
            valueofParameter[3] = SaoLuu.Thu3;
            ParameterColection[4] = "@Thu4";
            valueofParameter[4] = SaoLuu.Thu4;
            ParameterColection[5] = "@Thu5";
            valueofParameter[5] = SaoLuu.Thu5;
            ParameterColection[6] = "@Thu6";
            valueofParameter[6] = SaoLuu.Thu6;
            ParameterColection[7] = "@Thu7";
            valueofParameter[7] = SaoLuu.Thu7;
            ParameterColection[8] = "@DuongDan";
            valueofParameter[8] = SaoLuu.DuongDan;
            ParameterColection[9] = "@ThoiGian";
            valueofParameter[9] = SaoLuu.ThoiGian;
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        public int SaoLuuDuLieu(string DuongDan, string MatKhau)
        {
            int i = -1;
            string sql = "sp_BackupDatabase";
            string[] ParameterColection = new string[2];
            Object[] valueofParameter = new Object[2];
            ParameterColection[0] = "@DuongDan";
            valueofParameter[0] = DuongDan;
            ParameterColection[1] = "@MatKhau";
            valueofParameter[1] = MatKhau;
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }
    }
}
